<template>
  <!-- 图层管理按钮 -->
  <button class="layer-btn" @click="layerBoxShow = !layerBoxShow">
    图层
  </button>
  <!-- 图层管理复选框 -->
  <div v-show="layerBoxShow" class="layer-box">
    <div v-for="(item, index) in layerList" :key="index" style="position:relative">
      <input
        :id="item.id"
        type="checkbox"
        :checked="item.isChecked"
        class="tui-checkbox"
        @click="modifyIsChecked(item)"
      >
      <div class="label">{{ item.name }}</div>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from 'vue'
export default {
  emits: ['check'],
  setup(props, { emit }) {
    const data = reactive({
      layerList: [
        { name: '构造物', isChecked: true, id: 'structure' },
        { name: '问题', isChecked: true, id: 'problem' }
      ],
      layerBoxShow: false
    })

    const modifyIsChecked = (item) => {
      item.isChecked = !item.isChecked
      emit('check', item)
    //   switch (item.name) {
    //     case '构造物':
    //       data.structorLayer.setVisible(item.isChecked)
    //       hidestructureInfo()
    //       break
    //     case '问题':
    //       data.problemLayer.setVisible(item.isChecked)
    //       hideProblemInfo()
    //       break
    //     case '机场':
    //       data.airportLayer.setVisible(item.isChecked)
    //       hideAirportInfo()
    //   }
    }

    return {
      ...toRefs(data),
      modifyIsChecked
    }
  }

}
</script>

<style lang="scss" scoped>
//图层管理按钮
.layer-btn {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 50px;
  height: 32px;
  border: none;
  border-radius: 1px;
  background: rgba(0, 184, 180, 0.8);
  font-size: 16px;
  font-weight: 400;
  color: rgba(255, 255, 255, 1);
  cursor: pointer;
}
.layer-box {
  position: absolute;
  top: 18px;
  left: 75px;
  width: 88px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 1);
  padding: 6px;
  .label {
    font-size: 12px;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.7);
    position:absolute;
    height:13px;
    left:17px;
    top:0;
  }
}

.tui-checkbox:checked {
  background: #0dadd973;
  content: "✔";
  border: none;
  font-weight: 400;
  text-align: center;
}
.tui-checkbox {
  width: 13px;
  height: 13px;
  background-color: #ffffff;
  vertical-align:center;
  font-size: 12px;
  line-height: 13px;
  color: #fff;
  margin: 0;
  padding: 0;
  position: relative;
  display:inline-block;
  border: 1px solid rgba(53, 53, 53, 0.4);
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}
.tui-checkbox:checked::after {
  content: "✔";
  color: #fff;
  top: 0;
  left: 0;
  position: absolute;
  background: transparent;
  border-radius: 1px;
  border: none;
  height: 100%;
  width: 100%;
}
</style>
